package com.bjdd.jdy.ui.setting;


import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bjdd.jdy.R;
import com.bjdd.jdy.base.BaseActivity;
import com.bjdd.jdy.util.JumpUtil;
import com.bjdd.jdy.util.SpUtil;
import com.bjdd.jdy.util.StatusBarUtil;

import com.bjdd.jdy.view.other.CustomDialog;
import com.zhy.autolayout.AutoLinearLayout;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SettingActivity extends BaseActivity<SettingPresenter, SettingModel> implements SettingContract.View {
    @Bind(R.id.toolbar_back)
    ImageView toolbarBack;
    @Bind(R.id.title)
    TextView title;
    @Bind(R.id.all_setting_userinfo)
    AutoLinearLayout allSettingUserinfo;
    @Bind(R.id.all_setting_change_pwd)
    AutoLinearLayout allSettingChangePwd;
    @Bind(R.id.all_setting_suggestion)
    AutoLinearLayout allSettingSuggestion;
    @Bind(R.id.all_setting_login_out)
    AutoLinearLayout allSettingLoginOut;
    private CustomDialog mDialog;

    @Override
    public int getLayoutId() {
        return R.layout.activity_setting;
    }

    @Override
    public void initView() {
        StatusBarUtil.setColor(this, getResources().getColor(R.color.toolbar_bg),0);
        title.setText("设置");
    }


    @OnClick({R.id.toolbar_back, R.id.all_setting_userinfo, R.id.all_setting_change_pwd, R.id.all_setting_suggestion, R.id.all_setting_login_out})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.toolbar_back:
                finish();
                break;
            case R.id.all_setting_userinfo:
                JumpUtil.toUserCenter(context);
                break;
            case R.id.all_setting_change_pwd:
                JumpUtil.toResetPwd(context);
                break;
            case R.id.all_setting_suggestion:
                JumpUtil.toFeedBack(context);
                break;
            case R.id.all_setting_login_out:
                CustomDialog.Builder builder;
                builder = new CustomDialog.Builder(this);
                mDialog = builder.setMessage("确定退出登陆?")
                        .setPositiveButton("确定", new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                mDialog.dismiss();
                                presenter.setAlias("");

                            }
                        })
                        .setNegativeButton("取消", new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                mDialog.dismiss();
                            }
                        })
                        .createTwoButtonDialog();
                mDialog.show();
                break;
        }
    }

    @Override
    public void setAliasBack(int i) {
        if (i == 0){
            SpUtil.setUser(null);
            JumpUtil.toLogin(context);
            finish();
        }else {
            presenter.setAlias("");
        }
    }
}
